﻿$(function() {
    resetLeft();
        
    //左部菜单动画
    $("#split").toggle(
        function() {                   
            $(this).addClass("close").attr("title", "显示导航栏");                               
            parent.setLeftWidth(5);
            $('#split').css("left", "0px");                   
        }, function() {                                                         
            $(this).removeClass("close").attr("title", "隐藏导航栏");            
            var frameWidth = getFrameWidth();
            parent.setLeftWidth(frameWidth + 5);
            $('#split').css("left", frameWidth + "px");
        }
    );
    $(".leftBox div.title").toggle(
        function() { $(this).addClass("close").next().slideUp("fast", resetLeft); },
        function() { $(this).removeClass("close").next().slideDown("fast", resetLeft); }
    );
    $(".leftBox ul li a").click(function() {
        $(".leftBox ul li a").removeClass("current");
        $(this).addClass("current");
    });
   
    top.resetLeftMenu = resetLeft;
});

function resetLeft() {
    var main = $('#mainleft');
    var split = $('#split');
    var docHeight = document.documentElement.clientHeight - 2;
    main.height(docHeight);           
    var frameWidth = getFrameWidth();             
    main.width(frameWidth);
    split.css("left", frameWidth + "px").find('b').css("margin-top", (docHeight / 2 - 26) + "px");
    parent.setLeftWidth(frameWidth + 5);
}

function getFrameWidth() {
    var leftBox = document.getElementById('mainleft');           
    var hasScroll = (document.documentElement.clientHeight - 2) < leftBox.scrollHeight;
    return hasScroll ? 207 : 190;
}